﻿namespace FlexPlatform.BusinessLogic.DataModel
{
    using System.Collections.Generic;
    using System.Linq.Expressions;
    using FlexPlatform.GeneralUse;
    using FlexPlatform.Shared.DataModel;

    public class PropertyEnumeration<T> : IPropertyEnumeration<T> where T : IDataEntity
    {
        private Dictionary<string, LambdaExpression> clsFields;

        public PropertyEnumeration()
        {
            clsFields = new Dictionary<string,LambdaExpression>();
        }

        public bool ContainsField(string fieldName)
        {
            return clsFields.ContainsKey(fieldName);
        }

        public void AddField(Expression<System.Func<T, dynamic>> property)
        {
            var propertyName = ReflectionHelper.GetPropertyName(property);
            clsFields.Add(propertyName, property);
        }

        public IEnumerable<LambdaExpression> Fields
        {
            get
            {
                return clsFields.Values;
            }
        }
    }
}
